﻿using Cart.NguoiDungSrv;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Cart
{
    public partial class register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void register_button1_Click(object sender, EventArgs e)
        {
            //ScriptManager.RegisterStartupScript(this, this.GetType(), "Redit", "alert('Đăng ký thành công'); window.location='" + Request.ApplicationPath + "TrangChu.aspx';", true);
            //string str = "<script>alert(\"ok\");</script>";
            //Page.ClientScript.RegisterStartupScript(this.GetType(), "Script", str, false);
            using (var nguoidungService = new NguoiDungSrv.NguoiDungServiceClient())
            {
                var check = nguoidungService.CheckEmail(txtEmail.Text);
                if (check == true)
                {
                    var nguoidungmodel = new NguoiDung();
                    nguoidungmodel.Email = txtEmail.Text;
                    nguoidungmodel.MatKhau = txtPass.Text;
                    nguoidungmodel.DienThoai = txtDienThoai.Text;
                    nguoidungmodel.DiaChi = txtDiaChi.Text;
                    nguoidungmodel.HoTen = txtHoTen.Text;
                    var result = nguoidungService.CapNhatNguoiDung(nguoidungmodel);
                    Response.Redirect("~/TrangChu.aspx");
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Redit", "alert('Đăng ký" + result + "');", true);
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Redit", "alert('Email đã được sử dụng');", true);
                }
            }
            Response.Redirect("~/TrangChu.aspx");
        }
    }
}